package com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.dao.TcRevisitDao;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.ITcRevisitService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TcRevisitServiceImpl implements ITcRevisitService {
    @Autowired
    private TcRevisitDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    /**
     * tc随访
     *
     * @param page
     * @param searchInfo
     * @return
     */
    public List<TcRevisitInfo> selectPageListByRevisit(Page<TcRevisitInfo> page, SearchTcRevisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        String tableHead = searchInfo.getAbbreviation();
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartUpdateTime())) {
            params.put("startUpdateTime", searchInfo.getStartUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUpdateTime())) {
            params.put("endUpdateTime", searchInfo.getEndUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        params.put("outpatientName", searchInfo.getOutpatientName());
        params.put("tableName", tableHead +"customer_info");
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.selectPageListByRevisit(page, params);
    }

    @Override
    public int getQueryPagesRevisitCount(Page<TcRevisitInfo> page, SearchTcRevisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        String tableHead = searchInfo.getAbbreviation();
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartUpdateTime())) {
            params.put("startUpdateTime", searchInfo.getStartUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUpdateTime())) {
            params.put("endUpdateTime", searchInfo.getEndUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        params.put("outpatientName", searchInfo.getOutpatientName());
        params.put("tableName", tableHead +"customer_info");
        return dao.getQueryPagesRevisitCount(page, params);
    }

    public List<SfInfo> getSfList() {
        String sql = "select * from tc_follow_template where user='" + ShiroKit.getUser().getAccount() + "'";
        List<SfInfo> list = sqlMapper.selectList(sql, SfInfo.class);
        return list;
    }

    public List<SfInfo> getJgList() {
        String sql = "select * from tc_follow_results_template where user='" + ShiroKit.getUser().getAccount() + "'";
        List<SfInfo> list = sqlMapper.selectList(sql, SfInfo.class);
        return list;
    }

    public SfInfo getSfById(String id) {
        String sql = "select * from tc_follow_template where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }

    public SfInfo getJgById(String id) {
        String sql = "select * from tc_follow_results_template where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }
}